#include "Calculator.h"

CSSCalculator::CSSCalculator() {}

CSSCalculator::~CSSCalculator() {
  // SSCalculatorIF::instance()->destory();
}

void CSSCalculator::destory() { SSCalculatorIF::destory(); }

void CSSCalculator::setBondFundamentalInfo(
    const std::vector<SSSingleRawBondFundamentalInfo>& all_info) {
  SSCalculatorIF::instance()->setBondFundamentalInfo(all_info);
}

void CSSCalculator::addBondFundamentalInfo(
    const std::vector<SSSingleRawBondFundamentalInfo>& all_info) {
  SSCalculatorIF::instance()->addBondFundamentalInfo(all_info);
}

void CSSCalculator::setInterestRate(
    const std::vector<SSSingleInterestRate>& all_rates) {
  return SSCalculatorIF::instance()->setInterestRate(all_rates);
}

void CSSCalculator::setCalendar(
    const std::vector<SSSingleCalendar>& all_calendars) {
  return SSCalculatorIF::instance()->setCalendar(all_calendars);
}

// simple calculation
double CSSCalculator::accruedAmount(const std::string& bond_Key,
                                    const std::string& settlementDate) {
  return SSCalculatorIF::instance()->accruedAmount(bond_Key, settlementDate);
}

double CSSCalculator::dirtyPriceToCleanPrice(const std::string& bond_Key,
                                             const std::string& settlementDate,
                                             double dirtyPrice) {
  return SSCalculatorIF::instance()->dirtyPriceToCleanPrice(
      bond_Key, settlementDate, dirtyPrice);
}
double CSSCalculator::ytmToCleanPrice(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double ytm) {
  return SSCalculatorIF::instance()->ytmToCleanPrice(bond_Key, settlementDate,
                                                     ytm);
}
double CSSCalculator::marketSpreadToCleanPrice(
    const std::string& bond_Key, const std::string& settlementDate,
    double marketSpread) {
  return SSCalculatorIF::instance()->marketSpreadToCleanPrice(
      bond_Key, settlementDate, marketSpread);
}
double CSSCalculator::ytcToCleanPrice(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double ytc) {
  return SSCalculatorIF::instance()->ytcToCleanPrice(bond_Key, settlementDate,
                                                     ytc);
}
double CSSCalculator::ytpToCleanPrice(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double ytp) {
  return SSCalculatorIF::instance()->ytpToCleanPrice(bond_Key, settlementDate,
                                                     ytp);
}

double CSSCalculator::cleanPriceToDirtyPrice(const std::string& bond_Key,
                                             const std::string& settlementDate,
                                             double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToDirtyPrice(
      bond_Key, settlementDate, cleanPrice);
}
double CSSCalculator::cleanPriceToYTM(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToYTM(bond_Key, settlementDate,
                                                     cleanPrice);
}
double CSSCalculator::cleanPriceToMarketSpread(
    const std::string& bond_Key, const std::string& settlementDate,
    double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToMarketSpread(
      bond_Key, settlementDate, cleanPrice);
}
double CSSCalculator::cleanPriceToYTC(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToYTC(bond_Key, settlementDate,
                                                     cleanPrice);
}
double CSSCalculator::cleanPriceToYTP(const std::string& bond_Key,
                                      const std::string& settlementDate,
                                      double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToYTP(bond_Key, settlementDate,
                                                     cleanPrice);
}

double CSSCalculator::notional(const std::string& bond_Key,
                               const std::string& date) {
  return SSCalculatorIF::instance()->notional(bond_Key, date);
}

// cashflows
vector<SSSingleCashflow> CSSCalculator::cashflowsTable(
    const std::string& bond_Key, const std::string& settlementDate) {
  return SSCalculatorIF::instance()->cashflowsTable(bond_Key, settlementDate);
}

// basic calculation page
bool CSSCalculator::isFRNBond(
    const std::string& bond_Key)  // 判断是否是浮动债券
{
  return SSCalculatorIF::instance()->isFRNBond(bond_Key);
}
bool CSSCalculator::isOptionEmbedded(
    const std::string& bond_Key,
    const std::string& settlementDate)  // 判断是否含权
{
  return SSCalculatorIF::instance()->isOptionEmbedded(bond_Key, settlementDate);
}
bool CSSCalculator::isYTCAvailable(const std::string& bond_Key,
                                   const std::string& settlementDate) {
  return SSCalculatorIF::instance()->isYTCAvailable(bond_Key, settlementDate);
}
bool CSSCalculator::isYTPAvailable(const std::string& bond_Key,
                                   const std::string& settlementDate) {
  return SSCalculatorIF::instance()->isYTPAvailable(bond_Key, settlementDate);
}
bool CSSCalculator::isListed(const std::string& bond_Key,
                             const std::string& today) {
  return SSCalculatorIF::instance()->isListed(bond_Key, today);
}
double CSSCalculator::prevailingRate(
    const std::string& bond_Key,
    const std::string& settlementDate)  // 当前基础利率
{
  return SSCalculatorIF::instance()->prevailingRate(bond_Key, settlementDate);
}
SSBasicCalculationPage CSSCalculator::basicPageInitialize(
    const std::string& bond_Key,
    const std::string& settlementDate)  // 价格试算初始化
{
  return SSCalculatorIF::instance()->basicPageInitialize(bond_Key,
                                                         settlementDate);
}
SSBasicCalculationPage CSSCalculator::setCouponRateSpread(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate) {
  return SSCalculatorIF::instance()->setCouponRateSpread(
      bond_Key, settlementDate, couponRateSpread, indexRate);
}
SSBasicCalculationPage CSSCalculator::setIndexRate(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate) {
  return SSCalculatorIF::instance()->setIndexRate(bond_Key, settlementDate,
                                                  couponRateSpread, indexRate);
}
SSBasicCalculationPage CSSCalculator::clickPrevailingRate(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread) {
  return SSCalculatorIF::instance()->clickPrevailingRate(
      bond_Key, settlementDate, couponRateSpread);
}

SSBasicCalculationPage CSSCalculator::cleanPriceToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double cleanPrice) {
  return SSCalculatorIF::instance()->cleanPriceToAll(
      bond_Key, settlementDate, couponRateSpread, indexRate, cleanPrice);
}
SSBasicCalculationPage CSSCalculator::dirtyPriceToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double dirtyPrice) {
  return SSCalculatorIF::instance()->dirtyPriceToAll(
      bond_Key, settlementDate, couponRateSpread, indexRate, dirtyPrice);
}
SSBasicCalculationPage CSSCalculator::ytmToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double ytm) {
  return SSCalculatorIF::instance()->ytmToAll(bond_Key, settlementDate,
                                              couponRateSpread, indexRate, ytm);
}
SSBasicCalculationPage CSSCalculator::marketSpreadToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double marketSpread) {
  return SSCalculatorIF::instance()->marketSpreadToAll(
      bond_Key, settlementDate, couponRateSpread, indexRate, marketSpread);
}
SSBasicCalculationPage CSSCalculator::ytcToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double ytc) {
  return SSCalculatorIF::instance()->ytcToAll(bond_Key, settlementDate,
                                              couponRateSpread, indexRate, ytc);
}
SSBasicCalculationPage CSSCalculator::ytpToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double ytp) {
  return SSCalculatorIF::instance()->ytpToAll(bond_Key, settlementDate,
                                              couponRateSpread, indexRate, ytp);
}

// rebate mode
SSBasicCalculationPage CSSCalculator::rebateToAll(
    const std::string& bond_Key, const std::string& settlementDate,
    double couponRateSpread, double indexRate, double quotedYTM,
    double rebate) {
  return SSCalculatorIF::instance()->rebateToAll(
      bond_Key, settlementDate, couponRateSpread, indexRate, quotedYTM, rebate);
}

double CSSCalculator::futurePriceByDPAndIRR(const std::string& bond_Key,
                                            const std::string& tradeDate,
                                            const std::string& settlementDate,
                                            double convertFactor,
                                            double dirtyPrice, double irr) {
  return SSCalculatorIF::instance()->futurePriceByDPAndIRR(
      bond_Key, tradeDate, settlementDate, convertFactor, dirtyPrice, irr);
}
double CSSCalculator::dirtyPriceByFPAndIRR(const std::string& bond_Key,
                                           const std::string& tradeDate,
                                           const std::string& settlementDate,
                                           double convertFactor,
                                           double futurePrice, double irr) {
  return SSCalculatorIF::instance()->dirtyPriceByFPAndIRR(
      bond_Key, tradeDate, settlementDate, convertFactor, futurePrice, irr);
}
/*
// rebate mode
string CSSCalculator::listedDate (const std::string& bond_Key)
{
        return SSCalculatorIF::instance()->listedDate ( bond_Key) ;
}
SSBasicCalculationPage CSSCalculator::setCouponRateRebateMode (const
std::string& bond_Key, double coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->setCouponRateRebateMode ( bond_Key,
coupon_Rate_Spread);
}
SSBasicCalculationPage CSSCalculator::basicPageInitializeRebateMode(const
string& bond_Key)
{
        return SSCalculatorIF::instance()->basicPageInitializeRebateMode(
bond_Key) ;
}
// new Issue
SSBasicCalculationPage CSSCalculator::rebateToAllNewIssueRebateMode (const
string& bond_Key, double rebate, double indexRate, double coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->rebateToAllNewIssueRebateMode (
bond_Key, rebate, indexRate, coupon_Rate_Spread) ;
}
SSBasicCalculationPage CSSCalculator::dirtyPriceToAllNewIssueRebateMode (const
string& bond_Key, double dirtyPrice, double indexRate, double
coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->dirtyPriceToAllNewIssueRebateMode (
bond_Key, dirtyPrice, indexRate, coupon_Rate_Spread) ;
}
SSBasicCalculationPage CSSCalculator::ytmToAllNewIssueRebateMode (const
std::string& bond_Key, double ytm, double indexRate, double coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->ytmToAllNewIssueRebateMode (
bond_Key, ytm, indexRate, coupon_Rate_Spread) ;
}
SSBasicCalculationPage CSSCalculator::marketSpreadToAllNewIssueRebateMode (const
string& bond_Key, double marketSpread, double indexRate, double
coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->marketSpreadToAllNewIssueRebateMode (
bond_Key, marketSpread, indexRate, coupon_Rate_Spread);
}
SSBasicCalculationPage CSSCalculator::ytcToAllNewIssueRebateMode (const
std::string& bond_Key, double ytc, double indexRate, double coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->ytcToAllNewIssueRebateMode (
bond_Key, ytc, indexRate, coupon_Rate_Spread) ;
}
SSBasicCalculationPage CSSCalculator::ytpToAllNewIssueRebateMode (const
std::string& bond_Key, double ytp, double indexRate, double coupon_Rate_Spread)
{
        return SSCalculatorIF::instance()->ytpToAllNewIssueRebateMode (
bond_Key, ytp, indexRate, coupon_Rate_Spread);
}
// add Issue
SSBasicCalculationPage CSSCalculator::dirtyPriceToAllAddIssueRebateMode (const
string& bond_Key, double dirtyPrice, double indexRate, double
coupon_Rate_Spread, double rebate)
{
        return SSCalculatorIF::instance()->dirtyPriceToAllAddIssueRebateMode (
bond_Key, dirtyPrice, indexRate, coupon_Rate_Spread, rebate) ;
}
SSBasicCalculationPage CSSCalculator::ytmToAllAddIssueRebateMode (const
std::string& bond_Key, double ytm, double indexRate, double coupon_Rate_Spread,
double rebate)
{
        return SSCalculatorIF::instance()->ytmToAllAddIssueRebateMode (
bond_Key, ytm, indexRate, coupon_Rate_Spread, rebate);
}
SSBasicCalculationPage CSSCalculator::marketSpreadToAllAddIssueRebateMode (const
string& bond_Key, double marketSpread, double indexRate, double
coupon_Rate_Spread, double rebate)
{
        return SSCalculatorIF::instance()->marketSpreadToAllAddIssueRebateMode (
bond_Key, marketSpread, indexRate, coupon_Rate_Spread, rebate) ;
}
SSBasicCalculationPage CSSCalculator::ytcToAllAddIssueRebateMode (const
std::string& bond_Key, double ytc, double indexRate, double coupon_Rate_Spread,
double rebate)
{
        return SSCalculatorIF::instance()->ytcToAllAddIssueRebateMode (
bond_Key, ytc, indexRate, coupon_Rate_Spread, rebate) ;
}

SSBasicCalculationPage CSSCalculator::ytpToAllAddIssueRebateMode (const
std::string& bond_Key, double ytp, double indexRate, double coupon_Rate_Spread,
double rebate)
{
        return SSCalculatorIF::instance()->ytpToAllAddIssueRebateMode (
bond_Key, ytp, indexRate, coupon_Rate_Spread, rebate) ;
}
*/
// holding period yield page
// trade condition --> basic calculation page

// holding condition
vector<SSHoldingPeriodInterest> CSSCalculator::holdingPeriodInterests(
    const std::string& startDate, const std::string& endDate,
    const std::string& indexID, double spread, int fixingPeriodNumber,
    const std::string& fixingPeriodUnit, const std::string& simpleCompound,
    const std::string& interestBasis, int preceeds, double notional) {
  return SSCalculatorIF::instance()->holdingPeriodInterests(
      startDate, endDate, indexID, spread, fixingPeriodNumber, fixingPeriodUnit,
      simpleCompound, interestBasis, preceeds, notional);
}

double CSSCalculator::holdingCost(
    const std::vector<SSHoldingPeriodInterest>& vct) {
  return SSCalculatorIF::instance()->holdingCost(vct);
}

// result
SSHoldingPeriodResult CSSCalculator::holdingPeriodResult(
    const std::string& bond_Key, const std::string& startDate,
    const std::string& endDate, const std::string& today, double notional,
    double startCleanPrice, double startAccruedInterest,
    double startFrontDeskCommission, double startBackStageCommission,
    double endCleanPrice, double endAccruedInterest,
    double endFrontDeskCommission, double endBackStageCommission,
    double interestTax, double businessTax, double holdingCost,
    bool buyThenSell, int payHoldingCost) {
  return SSCalculatorIF::instance()->holdingPeriodResult(
      bond_Key, startDate, endDate, today, notional, startCleanPrice,
      startAccruedInterest, startFrontDeskCommission, startBackStageCommission,
      endCleanPrice, endAccruedInterest, endFrontDeskCommission,
      endBackStageCommission, interestTax, businessTax, holdingCost,
      buyThenSell, payHoldingCost);
}

double CSSCalculator::impliedRepoRate(const std::string& bond_Key,
                                      const std::string& tradeDate,
                                      const std::string& settlementDate,
                                      double futurePrice, double convertFactor,
                                      double dirtyPrice) {
  return SSCalculatorIF::instance()->impliedRepoRate(
      bond_Key, tradeDate, settlementDate, futurePrice, convertFactor,
      dirtyPrice);
}
std::string CSSCalculator::exceptions() {
  return SSCalculatorIF::instance()->exceptions();
}
